//package com.infore.statisticsAndAlarm.statistic;
//
//import java.sql.Connection;
//import java.sql.PreparedStatement;
//import java.sql.SQLException;
//import java.util.List;
//import java.util.Map;
//
//import javax.sql.DataSource;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import com.infore.statisticsAndAlarm.externalInterface.IDataReceivingService;
//import com.infore.statisticsAndAlarm.util.DateUtil;
//import com.infore.statisticsAndAlarm.util.ObjectMapperUtil;
//import com.infore.statisticsAndAlarm.util.ResultEntity;
//import com.infore.statisticsAndAlarm.util.ScaleUtil;
//import com.infore.statisticsAndAlarm.util.UUIDGenerator;
//
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//
//@Api(value = "统计时间段内的数据", tags = { "统计时间段内的数据" })
//@RestController
//@RequestMapping("/statisticHourAir")
//public class HourDataAirController {
//
//	@Autowired
//	DataSource DataSource;
//	@Autowired
//	IDataReceivingService iDataRecevingService;
//	@Autowired
//	private ObjectMapperUtil ObjectMapperUtil;
//	Connection connection = null;
//	PreparedStatement pstmt = null;
//
//	@ApiOperation(value = "统计时间段内的数据--通用接口")
//	@GetMapping(value = "/hourair")
//	public String hourAir() {
//		String message = "";
//		System.out.println(
//				"****************" + DateUtil.getCurrentDate(DateUtil.DATE_FULL_STR) + " 开始统计空气小时数据****************");
//		ResultEntity minuteEntity = iDataRecevingService.queryHourData();
//		List<Map<String, Object>> minuteData = ObjectMapperUtil.convertListMap(minuteEntity);
//		if (minuteData.size() == 0) {
//			System.out.println("暂无需要统计的数据！");
//		} else {
//			try {
//				connection = DataSource.getConnection();
//				String sql = "MERGE INTO hour_data_air T1 " + "using "
//						+ "(select count (*) NUM from hour_data_air a where a.data_time =to_date(?,'yyyy-MM-dd HH24') and a.factor_code =? and a.mn =? ) T2 "
//						+ "on (T2.NUM >0) " + "WHEN MATCHED THEN "
//						+ "  update set avg_value = ? where  data_time = to_date(?,'yyyy-MM-dd HH24') and factor_code =? and mn =? "
//						+ "WHEN NOT MATCHED THEN " + "  insert values(?,to_date(?,'yyyy-MM-dd HH24'),?,?,?,?,?)";
//				pstmt = connection.prepareStatement(sql);
//				int index = 0;
//				for (Map<String, Object> map : minuteData) {
//					String uuid = UUIDGenerator.getUUID();
//					String code = map.get("CODE").toString();
//					String mn = map.get("MN").toString();
//					String avg = map.get("VALUE") == null ? "0" : map.get("VALUE").toString();
//					String time = map.get("TIME").toString();
//					avg = ScaleUtil.sciCalSix(Double.valueOf(avg), 3);
//					pstmt.setString(1, time);
//					pstmt.setString(2, code);
//					pstmt.setString(3, mn);
//					pstmt.setString(4, avg);
//					pstmt.setString(5, time);
//					pstmt.setString(6, code);
//					pstmt.setString(7, mn);
//					pstmt.setString(8, uuid);
//					pstmt.setString(9, time);
//					pstmt.setString(10, code);
//					pstmt.setString(11, "N");
//					pstmt.setString(12, mn);
//					pstmt.setString(13, avg);
//					pstmt.setString(14, "0");
//					index++;
//					pstmt.execute();
//					// ResultEntity updateEntity = iDataRecevingService.updateHourData();
//					// int updateNum =(Integer) ((Map<String, Object>)
//					// updateEntity.getContent()).get("info");
//				}
//				message = "小时数据" + index + "条统计成功";
//				 pstmt.executeBatch();
//			} catch (Exception e) {
//				e.printStackTrace();
//			} finally {
//				try {
//					if (connection != null) {
//						connection.close();
//					}
//					if (pstmt != null) {
//						pstmt.close();
//					}
//				} catch (SQLException e) {
//					e.printStackTrace();
//				}
//			}
//		}
//		return message;
//	}
//
//}
